<?php
namespace app\index\controller;
use think\Db;
class Words
{
    /* 
    * 参数解析 
    * 参数1：wordId：这个是留言ID
    * 参数2：wordName：这个是留言人
    * 参数3：pageSize：这个是每次查询的数据条数
    * 参数4：currentPage：这是是查找第几页数据
    * */
    public function findWord(){
        $params = $_GET;
		$flag = true;
		$map;
		if($params['wordId'] != null || $params['wordId'] != ""){
			$flag = "false";
			$map['word_id'] = $params['wordId'];		
		}
		if($params['wordName'] != null || $params['wordName'] != ""){
			$flag = "false";
			$map['word_name'] =  array('like','%'.$params['wordName'].'%'); 	
		}
		if($flag == "true"){
			$data['data'] = Db::table('website_word')->order('worder_create_time desc')->limit($params['pageSize']*$params['currentPage'],$params['pageSize'])->select();
			$data['count'] = Db::table('website_word')->count();
		}else{
			$data['data'] = Db::table('website_word')->where($map)->order('worder_create_time desc')->limit($params['pageSize']*$params['currentPage'],$params['pageSize'])->select();
			$data['count'] = Db::table('website_word')->where($map)->count();
		}
        echo json_encode($data);
    }
    /*
	* 这是删除留言的方法 
	* 参数解析
	* 参数1：ids：这个是要删除的留言ID集合格式是（1,2,3）
	*/
	public function deleteWords(){
		$params = $_GET;
		// 这里是把前端的参数转换成一个数组进行操作
		$arr = explode(',',$params['ids']);
		$data['data'] = Db::table('website_word')->delete($arr);
		$data['message'] = "删除成功！";
		$data['status'] = "200";
		echo json_encode($data);
    }
    
}
